//
//  EPMPictureCell.m
//  WeiBoByOC
//
//  Created by 马继鵬 on 17/4/4.
//  Copyright © 2017年 7TH. All rights reserved.
//

#import "EPMPictureCell.h"

@interface EPMPictureCell()
@property (weak,nonatomic)  UIImageView* imgView;
@property (weak,nonatomic)  UIButton* deleteBtn;
@end

@implementation EPMPictureCell
- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]){
        [self setupUI];
    }
    return self;
}

- (void)setupUI{
    UIImageView* imgView = [[UIImageView alloc]init];
    _imgView = imgView;
    [self.contentView addSubview:imgView];
    [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
//    imgView.contentMode = UIViewContentModeCenter;
    UIButton* deleteBtn = [[UIButton alloc]init];
    _deleteBtn = deleteBtn;
    [self addSubview:deleteBtn];
    [deleteBtn setImage:[UIImage imageNamed:@"compose_photo_close"] forState:UIControlStateNormal];
    [deleteBtn addTarget:self action:@selector(deletePicture) forControlEvents:UIControlEventTouchUpInside];
    [deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.trailing.equalTo(self.contentView);
    }];
    [deleteBtn sizeToFit];
}

- (void)deletePicture{
    if (_deleteBtnBlock){
        self.deleteBtnBlock();
    }
}


- (void)setImg:(UIImage *)img{
    if(img == nil){
     self.imgView.image = [UIImage imageNamed:@"compose_pic_add"];
        self.deleteBtn.hidden = YES;
        return;
    }
    _img = img;
    self.imgView.image = img;
    self.deleteBtn.hidden = NO;
}

@end
